﻿using System.Windows;
using Samurai.WorkflowGraph.Views;
using Samurai.WorkflowGraph.Workflow;

namespace Samurai.WorkflowGraph
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        private readonly GraphWorkflow _graphWorkflow;

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            _graphWorkflow = new GraphWorkflow();
            Loaded += MainWindowLoaded;
        }

        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            _graphWorkflow.OnFailed(ex => MessageBox.Show(ex.Exception.Message));
            _graphWorkflow.OnCompleted(args =>
                                           {
                                               var view = new WorkflowGraphView();
                                               view.DataContext = _graphWorkflow.Context.GraphViewModel;
                                               GraphPresenter.Content = view;
                                           });
            _graphWorkflow.Start();
        }
    }
}
